473,441 Members | 2,091 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

insert item to dropdownlist using javascript

I can add items to my dropdown list using javascript like this:

cbo.length = j+2;

cbo.options[j].text = "Some Text";

cbo.options[j].value = "MyValue";

cbo.options[j+1].text = "Some Other Text";

cbo.options[j+1].value = "MyOtherValue";

But the above code adds them to the bottom of the list.

My question is how can add them back at a specific index in the list?
(I have a list of 10 items but remove two if they click an option button. If
they click back to the original value of the option group I want to add the
2 values back to the list. But in the right place.)

Any ideas?
--
Joe Fallon


Nov 19 '05 #1
2 13278
Joe,

First, remember the original index for the removed items.

Second, increment the ddl list by 2, as you do.

Third, move all options starting from the original position 2 positions up.
Do it in reverse order, starting from the highest position.

Forth, copy 2 removed item back to the original position.

Eliyahu

"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:eA*************@TK2MSFTNGP12.phx.gbl...
I can add items to my dropdown list using javascript like this:

cbo.length = j+2;

cbo.options[j].text = "Some Text";

cbo.options[j].value = "MyValue";

cbo.options[j+1].text = "Some Other Text";

cbo.options[j+1].value = "MyOtherValue";

But the above code adds them to the bottom of the list.

My question is how can add them back at a specific index in the list?
(I have a list of 10 items but remove two if they click an option button. If they click back to the original value of the option group I want to add the 2 values back to the list. But in the right place.)

Any ideas?
--
Joe Fallon

Nov 19 '05 #2
Elihayu,
Thanks for the tip.
I thought it might have to be something along those lines.

FYI - what I ended up doing was making a copy of the original list and then
using it to overwrite the modified list if they decided to change back. The
copy is only created once so they can toggle as many times as they want.
Seems to work fine.

Thanks again.
--
Joe Fallon


"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:uq**************@TK2MSFTNGP14.phx.gbl...
Joe,

First, remember the original index for the removed items.

Second, increment the ddl list by 2, as you do.

Third, move all options starting from the original position 2 positions
up.
Do it in reverse order, starting from the highest position.

Forth, copy 2 removed item back to the original position.

Eliyahu

"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:eA*************@TK2MSFTNGP12.phx.gbl...
I can add items to my dropdown list using javascript like this:

cbo.length = j+2;

cbo.options[j].text = "Some Text";

cbo.options[j].value = "MyValue";

cbo.options[j+1].text = "Some Other Text";

cbo.options[j+1].value = "MyOtherValue";

But the above code adds them to the bottom of the list.

My question is how can add them back at a specific index in the list?
(I have a list of 10 items but remove two if they click an option button.

If
they click back to the original value of the option group I want to add

the
2 values back to the list. But in the right place.)

Any ideas?
--
Joe Fallon


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Antonio D'Ottavio | last post by:
Good Morning, In my web page I've a datalist that is sourced by a database, the problem is that I want that one of the column of the datalist contain a dropdownbox that also is sourced by a table...
7
by: localhost | last post by:
A DataGrid with shows a label in one of the columns when in view mode. When in edit mode, I want to show a dropdown, and have the default selection set to what the textbox used to be. Right now...
3
by: Stephen Adam | last post by:
Hi there, I'm sure i'm missing something really simple here, all i want to do is get the value of the selected item in a list box. Even after much fiddling about last night I still could not get...
3
by: Sam C | last post by:
Hi, I have an ASP.Net page which has a DropDownList on it. The DDL is populated via a method which is called from the Page_Load if IsPostBack = False. When the form is submitted the...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
3
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the...
5
by: Me LK | last post by:
I need to add a line to choose a size into a dropdown . Since I have the dropdown nested inside a datagrid this is not working.When a page displays there are several rows of dropdowns but only the...
0
by: myselfgautam.kumar | last post by:
I have three records into Database. Two of them are already displayed into datagrid.Third record which is a parameter , I have to select it from dropdownlist and then insert that record into grid...
5
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration:...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.